package com.lyn.solitude.host_ui.adapter

import android.view.LayoutInflater
import android.view.ViewGroup
import com.bumptech.glide.Glide
import com.lyn.library.ui.adapter.ConvenientAdapter
import com.lyn.library.ui.adapter.viewHolder.ConvenientViewHolder
import com.lyn.solitude.entity.RemotePlugin
import com.lyn.solitude.host_ui.R
import com.lyn.solitude.host_ui.databinding.AdapterPluginStoreItemBinding

/**
 *
 * @author longyn 2024/05/29
 * @version 1.0.0
 */
class PluginStoreAdapter : ConvenientAdapter<RemotePlugin>() {
    override fun onBindConvenientViewHolder(
        holder: ConvenientViewHolder,
        position: Int,
        item: RemotePlugin?
    ) {
        val binding = holder.binding
        if (binding is AdapterPluginStoreItemBinding) {
            item?.let { remotePlugin ->
                Glide.with(binding.root)
                    .load(remotePlugin.logoUrl)
                    .fallback(R.drawable.img_plugin_icon)
                    .into(binding.logoImage)
                binding.name.text = remotePlugin.name
                binding.version.text = remotePlugin.version.toString()
            }
        }
    }

    override fun onCreateConvenientViewHolder(
        inflater: LayoutInflater,
        parent: ViewGroup,
        viewType: Int
    ): ConvenientViewHolder {
        val binding = AdapterPluginStoreItemBinding.inflate(inflater, parent, false)
        return ConvenientViewHolder(binding)
    }
}